//////////////////////////////////////////////////////////////////////////////////
//
//	DoD Shell Shock
//		- Version 1.3c
//		- 03.20.2007
//		- diamond-optic (original code by v3x)
//		- Stats: http://www.amxmodx.org/stats.php?mod_id=0&addon_id=48
//		- Servers: http://www.game-monitor.com/search.php?rulename=dod_shellshock_stats
//
//////////////////////////////////////////////////////////////////////////////////
//
// Credit:
//
//   - Original Code by v3x (he_damage_effect v0.2)
//   - Ported to DoD by diamond-optic
//   - cadav0r: new volume fx methods and various other fixes
//   - WARDOG: new ringing sound
//   - Emp`: suggestions on cleaning up some bits and pieces
//
// Information:
//
//   - When you take damage from allowed weapons, your
//     screen will be distorted & your sound volume will
//     decrease for a few seconds before it returns to
//     normal. There's also a ringing sound thats played
//     and an effect that changes how everything sounds.
//     I dont really know how to best explain all of this stuff...
//
//   - CVARs to pick which weapons cause effects
//   - Minimum damage required is controlled by cvars for each one of the effects...
//   - Each effect has cvars to control specific aspects of that effect..
//
// CVARS:
//
// 	dod_shellshock "1" 			//Turn on(1)/off(0)
//
// 	dod_shellshock_fade "1" 		//Turn on(1)/off(0) screen fade effect
// 	dod_shellshock_fade_dmg "20"		//Sets the minimum damage required
// 	dod_shellshock_fade_alpha "100" 	//Sets the defualt fade alpha level
// 	dod_shellshock_fade_inc "1" 		//Turn on(1)/off(0) increase of fade alpha level
// 	dod_shellshock_fade_inc_dmg "2"		//Amount of damage for each step of fade alpha level increase
// 	dod_shellshock_fade_inc_amt "5" 	//Fade alpha level increase amount per step 
//
//	dod_shellshock_vector "1"		//Turn on(1)/off(0) vector effect
// 	dod_shellshock_vector_dmg "50"		//Sets the minimum damage required
// 	dod_shellshock_vector_low "-60"		//Sets the minimum angle of change
// 	dod_shellshock_vector_high "60"		//Sets the maximum angle of change
//
// 	dod_shellshock_shake "1" 		//Turn on(1)/off(0) screen shake effect
// 	dod_shellshock_shake_dmg "30" 		//Sets the minimum damage required
//
// 	dod_shellshock_volume "1" 		//Turn on(1)/off(0) short volume loss effect
// 	dod_shellshock_volume_dmg "65" 		//Sets the minimum damage required
// 	dod_shellshock_volume_time1 "10"	//How long you lose volume (10ths of a second)
// 	dod_shellshock_volume_time2 "5"		//Delay between each volume increase step (10ths of a second)
// 	dod_shellshock_volume_inc "1"		//Turn on(1)/off(0) increase of volume loss time
// 	dod_shellshock_volume_inc_dmg "10"	//Amount of damage for each step of vol. loss increase
// 	dod_shellshock_volume_inc_time "1"	//Volume loss increase time per step (10ths of a second) 
//
// 	dod_shellshock_ring "1" 		//Turn on(1)/off(0) ringing effect
// 	dod_shellshock_ring_dmg "80" 		//Sets the minimum damage required
//
// 	dod_shellshock_fov "1" 			//Turn on(1)/off(0) fov effect
// 	dod_shellshock_fov_dmg "85" 		//Sets the minimum damage required
//
// 	dod_shellshock_sfx "1" 			//Turn on(1)/off(0) soundfx effect
// 	dod_shellshock_sfx_dmg "40" 		//Sets the minimum damage required
// 	dod_shellshock_sfx_time "20.0" 		//Sets how long the effect lasts (-1 = keep effect till client dies)
//
//	//weapons that cause effects
//	dod_shellshock_wpn_grenades "1"
//	dod_shellshock_wpn_rockets "1"
//	dod_shellshock_wpn_mortars "1"
//	dod_shellshock_wpn_knives "0"
//	dod_shellshock_wpn_spades "0"
//	dod_shellshock_wpn_buttstocks "0"
//	dod_shellshock_wpn_bayonets "0"
//
// Extra:
//
//      Put the "shellshock_ring_3.mp3" in /dod/sound/misc/
//
// Changelog:
//
//   - 05.01.2006 Version 0.1
//  	  Initial port of v3x's "he_damage_effect v0.2"
//  	  Added cvar to set min. dmg required
//	  Added Rockets as well as grenades
//
//   - 05.03.2006 Version 0.2
//  	  Added Garand & K43 buttstocks
//
//   - 05.05.2006 Version 0.3
//        Added CVAR for buttstocks
//	  Renamed to DoD Shell Shock
//
//   - 05.06.2006 Version 0.4
//        Removed buttstocks till I do it a better way
//        Changed from MSG_ONE to MSG_ONE_UNRELIABLE
//
//   - 05.10.2006 Version 0.5
//        Added CVARs for fade & shake (code from cadav0r)
//	  Added CVAR for volume
//
//   - 05.12.2006 Version 0.6
//        CVAR query bug fixed (thanks cadav0r)
//	  New method for volume effect (thanks cadav0r)
//	  Fixed volume staying at 0.0 bug
//
//   - 05.15.2006 Version 0.7
//	  Another fix for CVAR query problem
//        Added ringing sound MP3 (still plays during volume effect)
//	  Added CVAR for ringing effect
//	  Added FOV effect (defualts to 0 as im not satisfied with it yet)
//
//   - 05.18.2006 Version 0.7b
//	  Removed global damage cvar and added one for each effect
//
//   - 05.22.2006 Version 0.7c
//	  Fixed run-time error
//	  Adjusted a few random things...
//
//   - 05.24.2006 Version 0.7d
//	  Fixed 2 small errors becuase of my stupidity (thanks cadav0r)
//
//   - 06.09.2006 Version 0.8
//	  Added CVAR for how long you lose your volume
//	  Added CVAR for delay between each volume increase step (thanks cadav0r)
//	  New 'ringing' sound (thanks WARDOG)
//	  Adjusted ScreenFade & ScreenShake message variables
//
//   - 07.06.2006 Version 0.9
//	  Replaced ENGINE module with FAKEMETA module
//	  Fixed volume effect for multiple nade hits (thanks cadav0r)
//	  Added increasing of volume loss time depending on dmg (thanks cadav0r)
//	  Added CVAR for setting the fade effect's defualt alpha level
//	  Added increasing of fade alpha level depending on dmg (cadav0r's method)
//	  Added 4 CVARs to control vector effect settings
//	  Did some more work on the FOV effect, a little bit more satisfied with it
//
//   - 07.09.2006 Version 0.9b
//	  Removed FUN module
//
//   - 07.14.2006 Version 0.9c
//	  Fixed "Missing RIFF/WAVE chunk" console message
//
//   - 08.05.2006 Version 0.9d
//	  Fixed possible problem with ring sound not playing (thanks KidTwisted)
//	  Added RINGSOUND define to make it easy to use a different file
//	  Incase the volume global doesnt get set.. it defualts to 1.0
//	  Cleaned up code a bit...
//
//   - 08.28.2006 Version 1.0
//	  Added mortars, knives, spades, buttstocks, and bayonets
//	  Added CVARs to control which weapons cause the effect
//	  Changed some returns
//
//   - 09.21.2006 Version 1.1
//	  Added public cvar for stats tracking
//
//   - 12.16.2006 Version 1.2
//	  Cleaned up a bunch of things (thanks Emp`)
//
//   - 03.17.2007 Version 1.3
//	  Cleaned up some more things thru the code
//	  Changed the default values for some of the cvars
//	  Now the effects will stop if you die
//	  Improved the effect tasks
//	  Added a new feature: sfx (changes the way everything you hear sounds)
//
//   - 03.19.2007 Version 1.3b
//	  Fixed a typo in the CVAR comment section
//	  More simple way to stop all the effects at once
//	  Tasks are now removed on client disconnect
//	  Changed volume cvar query task from 10sec to 8sec
//	  Removed some plugin active checks (avoids problems when turning it on mid-game)
//	  Added RoundState checks
//
//   - 03.20.2007 Version 1.3c
//	  Removed an extra cvar (dod_shellshock_sfx_stay)
//	  Fixed the sfx effect time stuff
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <fakemeta>
#include <dodx>

//--------------------------------------------------------------------------------
#define RINGSOUND "sound/misc/shellshock_ring_3.mp3"	//ring sound fx file
//--------------------------------------------------------------------------------

// Task IDs
#define SFX_TASK  26372
#define FOV_TASK  71366
#define VOL_TASK  55183

new Float:gVolume[33] = { 1.0, ... }
new volumeup[33],gFov[33]
new bool:g_round_restart = false
new gMsgScreenShake , gMsgScreenFade, gMsgSetFOV, p_dod_shellshock
new p_dod_shellshock_fade, p_dod_shellshock_shake, p_dod_shellshock_volume, p_dod_shellshock_volume_time1, p_dod_shellshock_volume_time2, p_dod_shellshock_ring, p_dod_shellshock_fov
new p_dod_shellshock_fade_dmg, p_dod_shellshock_shake_dmg, p_dod_shellshock_volume_dmg, p_dod_shellshock_ring_dmg, p_dod_shellshock_fov_dmg
new p_dod_shellshock_volume_inc, p_dod_shellshock_vol_inc_dmg, p_dod_shellshock_vol_inc_time
new p_dod_shellshock_fade_alpha, p_dod_shellshock_fade_inc, p_dod_shellshock_fade_inc_dmg, p_dod_shellshock_fade_inc_amt
new p_dod_shellshock_vector, p_dod_shellshock_vector_dmg, p_dod_shellshock_vector_low, p_dod_shellshock_vector_high
new p_grenades, p_rockets, p_mortars, p_knives, p_spades, p_buttstocks, p_bayonets
new p_soundfx, p_soundfx_time, p_soundfx_dmg

public plugin_init()
{
	register_plugin("DoD Shell Shock","1.3c","AMXX DoD Team & v3x")
	
	//plugin stats public cvar
	register_cvar("dod_shellshock_stats", "1.3c", FCVAR_SERVER|FCVAR_SPONLY)
	
	//global on/off
	p_dod_shellshock = register_cvar("dod_shellshock","1")
	
	//weapons
	p_grenades = register_cvar("dod_shellshock_wpn_grenades","1")
	p_rockets = register_cvar("dod_shellshock_wpn_rockets","1")
	p_mortars = register_cvar("dod_shellshock_wpn_mortars","1")
	p_knives = register_cvar("dod_shellshock_wpn_knives","0")
	p_spades = register_cvar("dod_shellshock_wpn_spades","0")
	p_buttstocks = register_cvar("dod_shellshock_wpn_buttstocks","0")
	p_bayonets = register_cvar("dod_shellshock_wpn_bayonets","0")
	
	//fade
	p_dod_shellshock_fade = register_cvar("dod_shellshock_fade","1")
	p_dod_shellshock_fade_alpha = register_cvar("dod_shellshock_fade_alpha","100")
	p_dod_shellshock_fade_dmg = register_cvar("dod_shellshock_fade_dmg","20")
	p_dod_shellshock_fade_inc = register_cvar("dod_shellshock_fade_inc","1")
	p_dod_shellshock_fade_inc_dmg = register_cvar("dod_shellshock_fade_inc_dmg","2")
	p_dod_shellshock_fade_inc_amt = register_cvar("dod_shellshock_fade_inc_amt","5")
	
	//shake 
	p_dod_shellshock_shake = register_cvar("dod_shellshock_shake","1")
	p_dod_shellshock_shake_dmg = register_cvar("dod_shellshock_shake_dmg","30")
	
	//vector
	p_dod_shellshock_vector = register_cvar("dod_shellshock_vector","1")
	p_dod_shellshock_vector_dmg = register_cvar("dod_shellshock_vector_dmg","50")
	p_dod_shellshock_vector_low = register_cvar("dod_shellshock_vector_low","-60")
	p_dod_shellshock_vector_high = register_cvar("dod_shellshock_vector_high","60")
	
	//volume
	p_dod_shellshock_volume = register_cvar("dod_shellshock_volume","1")
	p_dod_shellshock_volume_dmg = register_cvar("dod_shellshock_volume_dmg","65")
	p_dod_shellshock_volume_time1 = register_cvar("dod_shellshock_volume_time1","10")	//10ths of a second
	p_dod_shellshock_volume_time2 = register_cvar("dod_shellshock_volume_time2","5")	//10ths of a second
	p_dod_shellshock_volume_inc = register_cvar("dod_shellshock_volume_inc","1")
	p_dod_shellshock_vol_inc_dmg = register_cvar("dod_shellshock_volume_inc_dmg","10")
	p_dod_shellshock_vol_inc_time = register_cvar("dod_shellshock_volume_inc_time","1")	//10ths of a second
	
	//ring
	p_dod_shellshock_ring = register_cvar("dod_shellshock_ring","1")
	p_dod_shellshock_ring_dmg = register_cvar("dod_shellshock_ring_dmg","80")
	
	//fov
	p_dod_shellshock_fov = register_cvar("dod_shellshock_fov","1")
	p_dod_shellshock_fov_dmg = register_cvar("dod_shellshock_fov_dmg","85")
	
	//sound fx
	p_soundfx = register_cvar("dod_shellshock_sfx","1")
	p_soundfx_dmg = register_cvar("dod_shellshock_sfx_dmg","40")
	p_soundfx_time = register_cvar("dod_shellshock_sfx_time","20")
	
	//messages
	gMsgScreenShake = get_user_msgid("ScreenShake")
	gMsgScreenFade = get_user_msgid("ScreenFade")
	gMsgSetFOV = get_user_msgid("SetFOV")
	
	//damage & death forwards
	register_statsfwd(XMF_DAMAGE)
	register_statsfwd(XMF_DEATH)
	
	//RoundState event
	register_event("RoundState", "round_message", "a", "1=1", "1=3", "1=4")
}

public plugin_precache()
{
	precache_generic(RINGSOUND)
}

public client_putinserver(id)
{
	if(!is_user_bot(id) && is_user_connected(id))
		{
		client_cmd(id,"room_type 0")
		
		set_task(8.0,"cvar_query",id)
		}
}

public client_disconnect(id)
{
	if(get_pcvar_num(p_dod_shellshock) && !is_user_connected(id) && !is_user_bot(id))
		{
		//volume
		if(task_exists(VOL_TASK+id))
			remove_task(VOL_TASK+id)
	
		volumeup[id] = 0
	
		//fov
		if(task_exists(FOV_TASK+id))
			remove_task(FOV_TASK+id)
			
		//sfx
		if(task_exists(SFX_TASK+id))
			remove_task(SFX_TASK+id)
		}
}
		
public cvar_query(id)
{		
	if(!is_user_bot(id) && is_user_connected(id))
		query_client_cvar(id ,"volume","cvar_result")
}

public cvar_result(id,const cvar[],const value[])
{
	if (!is_user_bot(id) && is_user_connected(id))
		{
		gVolume[id] = str_to_float(value)
	
		if(gVolume[id] == 0.0)
			{
			client_cmd(id,"volume 1.0")
				
			gVolume[id] = 1.0
			}
		}
}

public dod_client_spawn(id)
{
	if(get_pcvar_num(p_dod_shellshock) && is_user_connected(id) && is_user_alive(id) && !is_user_bot(id))
		stop_all_effects(id)
}

public client_death(killer,victim,wpnindex,hitplace,TK)
{
	if(get_pcvar_num(p_dod_shellshock) && is_user_connected(victim) && !is_user_alive(victim) && !is_user_bot(victim))
		stop_all_effects(victim)
}

public client_damage(attacker,victim,damage,wpnindex,hitplace,TA)
{	
	if(!get_pcvar_num(p_dod_shellshock) || !is_user_connected(victim) || !is_user_alive(victim) || is_user_bot(victim) || g_round_restart)
		return PLUGIN_CONTINUE
	
	if((get_pcvar_num(p_grenades) && (wpnindex == DODW_HANDGRENADE || wpnindex == DODW_STICKGRENADE || wpnindex == DODW_MILLS_BOMB || wpnindex == DODW_STICKGRENADE_EX || wpnindex == DODW_HANDGRENADE_EX))
		|| (get_pcvar_num(p_rockets) && (wpnindex == DODW_PANZERSCHRECK || wpnindex == DODW_BAZOOKA || wpnindex == DODW_PIAT))
		|| (get_pcvar_num(p_mortars) && (wpnindex == DODW_MORTAR))
		|| (get_pcvar_num(p_knives) && (wpnindex == DODW_AMERKNIFE || wpnindex == DODW_GERKNIFE || wpnindex == DODW_BRITKNIFE))
		|| (get_pcvar_num(p_spades) && (wpnindex == DODW_SPADE))
		|| (get_pcvar_num(p_buttstocks) && (wpnindex == DODW_K43_BUTT || wpnindex == DODW_GARAND_BUTT))
		|| (get_pcvar_num(p_bayonets) && (wpnindex == DODW_KAR_BAYONET || wpnindex == DODW_ENFIELD_BAYONET)))
			shellshock_fx(victim,damage)

	return PLUGIN_CONTINUE
}

public shellshock_fx(victim,damage)
{
	if(!is_user_connected(victim) || !is_user_alive(victim) || is_user_bot(victim))
		return PLUGIN_HANDLED
		
	new param[1]
	param[0] = victim
	
	if(get_pcvar_num(p_dod_shellshock_ring) && damage >= get_pcvar_num(p_dod_shellshock_ring_dmg))
		client_cmd(victim,"mp3 play %s",RINGSOUND)
    
	if(get_pcvar_num(p_dod_shellshock_volume) && damage >= get_pcvar_num(p_dod_shellshock_volume_dmg))
		{
		if(task_exists(VOL_TASK+victim))
			remove_task(VOL_TASK+victim)
			
		client_cmd(victim,"volume 0")
		volumeup[victim] = 0
	
		new noVolume,noVolume2
		noVolume = get_pcvar_num(p_dod_shellshock_volume_time1)
		if (noVolume < 1)
			noVolume = 1

		if(get_pcvar_num(p_dod_shellshock_volume_inc))
			{
			new IncVolumeTime,Volumedmg,Incdmg,IncVolumedmg,inc
			IncVolumeTime = get_pcvar_num(p_dod_shellshock_vol_inc_time)
			if (IncVolumeTime < 1)
				IncVolumeTime = 1

			Volumedmg = get_pcvar_num(p_dod_shellshock_volume_dmg)
			Incdmg = get_pcvar_num(p_dod_shellshock_vol_inc_dmg)
		
			IncVolumedmg = Volumedmg
			inc = 0

			while(IncVolumedmg < 100)
				{
				++inc
				IncVolumedmg = Volumedmg + (inc*Incdmg)
				if(damage > Volumedmg && damage >= IncVolumedmg) 
					noVolume2 = noVolume + (inc*IncVolumeTime)
				else if(damage < (Volumedmg + Incdmg)) 
					noVolume2 = noVolume
				}
			}
		else
			{
			noVolume2 = noVolume
			}
		
		new Float:noVolumeTime
		noVolumeTime = floatdiv(float(noVolume2),10.0)
		
		set_task(noVolumeTime,"volume_up",VOL_TASK+victim, param, 1)
		}
		
	if(get_pcvar_num(p_dod_shellshock_vector) && damage >= get_pcvar_num(p_dod_shellshock_vector_dmg))
		{ 
		new Float:fVec[3]
		new Float:vec_low = get_pcvar_float(p_dod_shellshock_vector_low)
		new Float:vec_high = get_pcvar_float(p_dod_shellshock_vector_high)
		
		fVec[0] = random_float(vec_low, vec_high)
		fVec[1] = random_float(vec_low, vec_high)
		fVec[2] = random_float(vec_low, vec_high)
		set_pev(victim,pev_punchangle,fVec)
		}
			
	if(get_pcvar_num(p_dod_shellshock_shake) && damage >= get_pcvar_num(p_dod_shellshock_shake_dmg))
		{     
		message_begin(MSG_ONE_UNRELIABLE,gMsgScreenShake,{0,0,0},victim)
		write_short(1<<14) //ammount 
		write_short(1<<12) //lasts this long 
		write_short(2<<14) //frequency
		message_end()
		}
	
	if(get_pcvar_num(p_dod_shellshock_fade) && damage >= get_pcvar_num(p_dod_shellshock_fade_dmg))
		{
		new alpha2
		new alpha = get_pcvar_num(p_dod_shellshock_fade_alpha)
		
		if(alpha < 1)
			alpha = 1
		
		if(get_pcvar_num(p_dod_shellshock_fade_inc))
			{
			new IncFadeAmt,Fadedmg,Incdmg,IncFadedmg,inc
			IncFadeAmt = get_pcvar_num(p_dod_shellshock_fade_inc_amt)
			if (IncFadeAmt < 1)
				IncFadeAmt= 1

			Fadedmg = get_pcvar_num(p_dod_shellshock_fade_dmg)
			Incdmg = get_pcvar_num(p_dod_shellshock_fade_inc_dmg)
		
			IncFadedmg = Fadedmg
			inc = 0

			while(IncFadedmg < 100)
				{
				++inc
				IncFadedmg = Fadedmg + (inc*Incdmg)
				if(damage > Fadedmg && damage >= IncFadedmg) 
					alpha2 = alpha + (inc*IncFadeAmt)
				else if(damage < (Fadedmg + Incdmg)) 
					alpha2 = alpha
				}
			}
		else
			{
			alpha2 = alpha
			}
			
		if(alpha2 > 255)
			alpha2 = 255
			
		message_begin(MSG_ONE_UNRELIABLE,gMsgScreenFade,{0,0,0},victim)
		write_short(1<<13)  //duraiton  (old - 1<<11)
		write_short(1<<12)  //hold time  (old - 1<<10)
		write_short(0x0002)  //flags  (old - 1<<12)
		write_byte(192) //red
		write_byte(0) //green
		write_byte(0) //blue
		write_byte(alpha2) //alpha (160)
		message_end()
		}
	
	if(get_pcvar_num(p_dod_shellshock_fov) && damage >= get_pcvar_num(p_dod_shellshock_fov_dmg))
		{
		if(task_exists(FOV_TASK+victim))
			remove_task(FOV_TASK+victim)
			
		message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},victim)
		write_byte(170)
		message_end()
	
		gFov[victim] = 170
		
		set_task(0.2,"reset_fov",FOV_TASK+victim, param, 1)
		}
		
	if(get_pcvar_num(p_soundfx) && damage >= get_pcvar_num(p_soundfx_dmg))
		{
		if(task_exists(SFX_TASK+victim))
			remove_task(SFX_TASK+victim)
			
		if(random_num(0,1) == 1)
			{	
			client_cmd(victim,"room_type 14")
		
			client_cmd(victim,"wait;room_delay 0.65;room_feedback 0.6;room_left 8; room_lp 1;room_mod 0.45;room_refl 0.74;room_size 0.8")
			}
		else
			{
			client_cmd(victim,"room_type 19")
		
			client_cmd(victim,"wait;room_delay 20;room_feedback 0.78;room_left 14;room_lp 1;room_mod 0.1;room_refl 0.92;room_size 3.25")			
			}
					
		new Float:sfxTime = get_pcvar_float(p_soundfx_time)
				
		if(sfxTime == 0.0)
			sfxTime = 1.0
			
		if(sfxTime > 0.0)				
			set_task(sfxTime,"reset_sfx",SFX_TASK+victim, param, 1)
			
		}
		
	return PLUGIN_CONTINUE
}

public round_message() 
{
	if(get_pcvar_num(p_dod_shellshock))
		{
		new data = read_data(1)
			
		if(data == 1)
			g_round_restart = false
		else if(data == 3 || data == 4)
			{
			g_round_restart = true
		    
			new counter, players[32], totalPlayers
			get_players(players, totalPlayers, "ac")
			
			for(counter = 0; counter < totalPlayers; counter++)
				{
				stop_all_effects(players[counter])
				}
			}
		}
}

public volume_up(param[])
{
	new id = param[0]
	
	if(is_user_bot(id) || !is_user_connected(id) || !is_user_alive(id))
		return PLUGIN_HANDLED
	  
	new Float:set_value,Float:set_time
	
	set_value = floatdiv(float(volumeup[id] + 1),10.0)
	set_time = get_pcvar_float(p_dod_shellshock_volume_time2)
	 
	if(set_time < 1.0)
		set_time = 1.0
		
	set_time = floatdiv(set_time,10.0)
	    
	if(set_value < gVolume[id]) 
		{
		client_cmd(id,"volume %f",set_value)
		++volumeup[id]
		set_task(set_time,"volume_up",VOL_TASK+id, param, 1)
		} 
	else
		{
		client_cmd(id,"volume %f",gVolume[id])
		volumeup[id] = 0
		}
	return PLUGIN_HANDLED
}

public reset_fov(param[])
{
	new id = param[0]
	
	if(is_user_bot(id) || !is_user_connected(id) || !is_user_alive(id))
		return PLUGIN_HANDLED
   
	if(gFov[id] > 90) 
		{	
		message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},id)
		write_byte(gFov[id])
		message_end()
		
		gFov[id] = gFov[id] - 2
		
		set_task(0.1,"reset_fov",FOV_TASK+id, param, 1)
		} 
	else
		{ 
		message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},id)
		write_byte(90)
		message_end()
		}
	return PLUGIN_HANDLED
}

public reset_sfx(param[])
{
	new id = param[0]
	
	if(is_user_bot(id) || !is_user_connected(id) || !is_user_alive(id))
		return PLUGIN_HANDLED
	
	message_begin(MSG_ONE_UNRELIABLE,gMsgScreenFade,{0,0,0},id)
	write_short(1<<10)  //duraiton
	write_short(1<<10)  //hold time
	write_short(0x0002)  //flags
	write_byte(100) //red
	write_byte(0) //green
	write_byte(0) //blue
	write_byte(100) //alpha
	message_end()
		
	message_begin(MSG_ONE_UNRELIABLE,get_user_msgid("ScreenShake"),{0,0,0},id)
	write_short(1<<12) //ammount 
	write_short(2<<12) //lasts this long 
	write_short(160) //frequency
	message_end()
	
	client_cmd(id,"room_type 0")
	
	return PLUGIN_HANDLED
}

public stop_all_effects(id)
{
	if(is_user_connected(id) && !is_user_bot(id))
		{
		//ring
		client_cmd(id,"mp3 stop")
	
		//volume
		if(task_exists(VOL_TASK+id))
			remove_task(VOL_TASK+id)
	
		client_cmd(id,"volume %f",gVolume[id])
		volumeup[id] = 0
	
		//fov
		if(task_exists(FOV_TASK+id))
			remove_task(FOV_TASK+id)
		
		message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},id)
		write_byte(90)
		message_end()
	
		//sfx
		if(task_exists(SFX_TASK+id))
			remove_task(SFX_TASK+id)
		
		client_cmd(id,"room_type 0")
		}
}
